//
//  MsgViewController.m
//  FuncFanc
//
//  Created by hubing on 2018/3/5.
//  Copyright © 2018年 huhu. All rights reserved.
//

#import "MsgViewController.h"
#import "PoetryViewController.h"
@interface MsgViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray *_titleArray ;
}
@property (nonatomic,strong) UITableView *tableview;
@property (nonatomic,strong) Poem *poem;

@end

@implementation MsgViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGBOF(0xf1f1f1);
    self.title = @"总目录";

    _titleArray = @[@"唐诗目录",@"宋诗目录",@"宋词目录"];
    _tableview = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    [self.view addSubview:_tableview];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self loadData];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _titleArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%@",_titleArray[indexPath.row]];
    if (indexPath.row == 0) {
        
        cell.detailTextLabel.text = [NSString stringWithFormat:@"含%ld位诗人，共%ld首诗",_poem.author.tangPoets.count,_poem.tangPoem.count];
    }else if (indexPath.row == 1){
        cell.detailTextLabel.text = [NSString stringWithFormat:@"含%ld位诗人，共%ld首诗",_poem.author.songPoets.count,_poem.songPoem.count];
    }else if (indexPath.row == 2){
        cell.detailTextLabel.text = [NSString stringWithFormat:@"含%ld位诗人，共%ld首诗",_poem.author.lyricPoets.count,_poem.songCi.count];
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PoetryViewController *view = [[PoetryViewController alloc]init];
    view.hidesBottomBarWhenPushed = NO;
    [self.navigationController pushViewController:view animated:NO];
}

-(void)loadData
{
    __weak typeof(self) ws = self;
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        ws.poem = [[Poem alloc]init];
//        [ws.poem loadPoem];
        dispatch_async(dispatch_get_main_queue(), ^{
            [ws.tableview reloadData];
        });
    });
}

@end
